package com.easy.customer.controller;

import com.easy.common.bean.CustomerContacts;
import com.easy.common.service.ICustomerContactsService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("contact")
public class CustomerContactsController {

    @Autowired
    private ICustomerContactsService customerContactsService;

    @PostMapping
    public ResultData insert(@RequestBody CustomerContacts contacts) {
        CustomerContacts result = customerContactsService.insert(contacts);
        return ResultData.success(result);
    }

    @PutMapping
    public ResultData update(@RequestBody CustomerContacts contacts) {
        CustomerContacts result = customerContactsService.update(contacts);
        return ResultData.success(result);
    }

    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id) {
        int result = customerContactsService.delete(id);
        if (result > 0) {
            return ResultData.success();
        }
        return ResultData.fail();
    }

    @PutMapping("/setPrimary/{id}")
    public ResultData setPrimary(@PathVariable Integer id) {
        int result = customerContactsService.setPrimary(id);
        if (result > 0) {
            return ResultData.success();
        }
        return ResultData.fail();
    }
}